import 'package:flutter/material.dart';
import '../../helper/global_config.dart';
import '../../helper/routeHelper.dart';
import '../../model/xhss.dart';
import '../../widgets/IconWidget.dart';
import '../../helper/Helper.dart';
import '../../helper/global_config.dart';
import '../../helper/routeHelper.dart';
import '../../model/xhss.dart';
import '../../model/xhsskd.dart';
import '../../model/xhsszt.dart';
import '../../widgets/IconWidget.dart';
import '../../widgets/dialogWidget.dart';

import 'xhss_home.dart';

class XHSSHelper {
  static String getName(int id) {
    if (id == 0) return "冲沙放空洞";
    if (id == 1) return "1#泄洪洞";
    if (id == 2) return "2#泄洪洞";
    if (id == 3) return "溢洪道";

    return "出错";
  }

  static String getState(int id, double kd) {
    if (id == 1) {
      if (kd > 0) {
        return "过流";
      } else {
        return "正常";
      }
    }
    if (id == 2) return "检查维修";
    if (id == 3) return "环氧待强";

    return "出错";
  }

  static Color getColor(int id, double kd) {
    if (id == 1) {
      if (kd > 0) {
        return Colors.blue;
      } else {
        return Colors.green;
      }
    }
    if (id == 2) return Colors.red;
    if (id == 3) return Colors.orangeAccent;

    return Colors.black87;
  }

  static Widget getXHSSZTCard(BuildContext ctx, XHSSZT x1) {
    return Card(
      child: Column(children: getWidgetList2(ctx, x1)),
      color: GlobalConfig.cardBackgroundColor,
      margin: const EdgeInsets.only(top: 5.0, bottom: 5.0),
      // margin: const EdgeInsets.all(6.0),
      shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
    );
  }

  static Widget getXHSSKDCard(BuildContext ctx, XHSSKD x1) {
    return Card(
      child: ListTile(
        title: Text(getName(x1.TypeId)),
        trailing: Text(x1.KD2.toString()),
        subtitle: Text(Helper.DateTimeFormat(x1.TZTM)),
      ),
      color: GlobalConfig.cardBackgroundColor,
      margin: const EdgeInsets.only(top: 5.0, bottom: 5.0),
      // margin: const EdgeInsets.all(6.0),
      shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
    );
  }

  static Widget getXHSSCard(BuildContext ctx, XHSS x1) {
    return Card(
      child: Column(children: getWidgetList(ctx, x1)),
      color: GlobalConfig.cardBackgroundColor,
      margin: const EdgeInsets.all(6.0),
    );
  }

  static List<Widget> getWidgetList(BuildContext ctx, XHSS x1) {
    print(x1.State);
    List<Widget> list1 = <Widget>[];
    list1.add(ListTile(
      leading: Container(
          width: 24.0,
          height: 24.0,
          child: IconWidget.XHSSImage2(getColor(x1.State, x1.Kd))),
      title: Text(getName(x1.TypeId)),
      trailing: Text(getState(x1.State, x1.Kd)),
      onTap: () {
        RouteHelper.ShowPage(ctx, XHSSHome(x1.TypeId));
      },
    ));

    if (x1.State == 1) {
      list1.add(Divider(
        height: 0.0,
      ));
      list1.add(
        ListTile(
          title: Text("当前开度"),
          trailing: Text(Helper.StrNull(x1.Kd.toString())),
        ),
      );
      list1.add(
        Divider(
          height: 0.0,
        ),
      );
      list1.add(
        ListTile(
          title: Text("累计泄流时间"),
          trailing: Text(x1.Hours.toString() + "小时"),
        ),
      );
    }

    if (x1.State == 2) {
      list1.add(Divider(
        height: 0.0,
      ));
      list1.add(
        ListTile(
          title: Text("检修开始日期"),
          trailing: Text(Helper.StrNull(Helper.DateTimeFormat2(x1.BeginTM))),
        ),
      );
      list1.add(
        Divider(
          height: 0.0,
        ),
      );
      list1.add(
        ListTile(
          title: Text("预计完成日期"),
          trailing: Text(Helper.DateTimeFormat2(x1.EndTM)),
        ),
      );
    }

    if (x1.State == 3) {
      list1.add(Divider(
        height: 0.0,
      ));
      list1.add(
        ListTile(
          title: Text("开始日期"),
          trailing: Text(Helper.DateTimeFormat2(Helper.StrNull(x1.BeginTM))),
        ),
      );
      list1.add(
        Divider(
          height: 0.0,
        ),
      );
      list1.add(
        ListTile(
          title: Text("完成日期"),
          trailing: Text(Helper.DateTimeFormat2(x1.EndTM)),
        ),
      );
      list1.add(
        Divider(
          height: 0.0,
        ),
      );
      list1.add(
        ListTile(
          title: Text("具备过流条件时间"),
          trailing: Text(Helper.DateTimeFormat(x1.OKTM)),
        ),
      );
    }

    return list1;
  }

  static List<Widget> getWidgetList2(BuildContext ctx, XHSSZT x1) {
    print(x1.State);
    List<Widget> list1 = <Widget>[];
    list1.add(
      ListTile(
        title: Text(getName(x1.TypeId)),
        trailing: Text(getState(x1.State, 0)),
        /*
         onLongPress: () {
                showDialog(
                    context: ctx,
                    builder: (BuildContext context) {
                      return DialogWidget.getDialog(
                          context, "删除记录", "点击确定将删除该记录", () {
                        //exitLogin(context);

                        ;
                      });
                    });
              }*/
      ),
    );

    if (x1.State == 1) {
      list1.add(Divider(
        height: 0.0,
      ));
      list1.add(
        ListTile(
          title: Text("开始日期"),
          trailing: Text(Helper.DateTimeFormat2(x1.BeginTM)),
        ),
      );
    }

    if (x1.State == 2) {
      list1.add(Divider(
        height: 0.0,
      ));
      list1.add(
        ListTile(
          title: Text("检修开始日期"),
          trailing: Text(Helper.StrNull(Helper.DateTimeFormat2(x1.BeginTM))),
        ),
      );
      list1.add(
        Divider(
          height: 0.0,
        ),
      );
      list1.add(
        ListTile(
          title: Text("预计完成日期"),
          trailing: Text(Helper.DateTimeFormat2(x1.EndTM)),
        ),
      );
    }

    if (x1.State == 3) {
      list1.add(Divider(
        height: 0.0,
      ));
      list1.add(
        ListTile(
          title: Text("开始日期"),
          trailing: Text(Helper.DateTimeFormat2(Helper.StrNull(x1.BeginTM))),
        ),
      );
      list1.add(
        Divider(
          height: 0.0,
        ),
      );
      list1.add(
        ListTile(
          title: Text("完成日期"),
          trailing: Text(Helper.DateTimeFormat2(x1.EndTM)),
        ),
      );
      list1.add(
        Divider(
          height: 0.0,
        ),
      );
      list1.add(
        ListTile(
          title: Text("具备过流条件时间"),
          trailing: Text(Helper.DateTimeFormat(x1.OKTM)),
        ),
      );
    }

    return list1;
  }
}
